﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;

namespace ZkSurvey.Web.WS
{
    public class TableRowResult
    {
        public int id = -1;
        public bool success = false;
        public string message = "";
    }

    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [GenerateScriptType(typeof(TableRowResult))]
    [ScriptService]
    public class AjaxTable :
        System.Web.Services.WebService
    {
        [WebMethod(true)]
        //[WebMethod(true)] enable session
        public TableRowResult AddRow(int tblID, string rowContent)
        {
            TableRowResult result = new TableRowResult();

            //TableRow row = null;
            //List<TableRowColumn> columns = null;

            //try
            //{
            //    columns = FormatedTableRow.Convert(rowContent);

            //    row = new TableBl().AddRow(tblID, -1, columns);

            //    result.id = row.ID;
            //}
            //catch (Exception ex)
            //{
            //    result.id = -1;
            //    result.success = false;
            //    result.message = ex.Message;
            //    return result;
            //}

            result.success = true;
            return result;
        }

        [WebMethod(true)]
        //[WebMethod(true)] enable session
        public TableRowResult EditRow(int rowID, string rowContent)
        {
            TableRowResult result = new TableRowResult();

            //List<TableRowColumn> columns = null;

            //try
            //{
            //    columns = FormatedTableRow.Convert(rowContent);

            //    new TableBl().EditRow(rowID, columns);

            //    result.id = rowID;
            //}
            //catch (Exception ex)
            //{
            //    result.id = -1;
            //    result.success = false;
            //    result.message = ex.Message;
            //    return result;
            //}

            result.success = true;
            return result;
        }


        [WebMethod(true)]
        //[WebMethod(true)] enable session
        public TableRowResult RemoveRow(int rowID)
        {
            TableRowResult result = new TableRowResult();

            //try
            //{
            //    new TableBl().RemoveRow(rowID);

            //    result.id = rowID;
            //}
            //catch (Exception ex)
            //{
            //    result.id = -1;
            //    result.success = false;
            //    result.message = ex.Message;
            //    return result;
            //}

            result.success = true;
            return result;
        }
    }
}
